/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ericsson.nfc.signing;

import com.ericsson.nfc.signing.algorithm.PrivateKey;
import com.ericsson.nfc.signing.algorithm.SignatureException;
import com.ericsson.nfc.signing.algorithm.Signer;
import com.ericsson.nfc.signing.record.CertificateBytes;
import com.ericsson.nfc.signing.record.URIRecord;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.MD5Digest;

//#ifdef MyJSR257
//# import my.javax.microedition.contactless.ndef.NDEFRecordType;
//# import my.javax.microedition.contactless.ndef.NDEFRecord;
//# import my.javax.microedition.contactless.ndef.NDEFRecordType;
//#else
import javax.microedition.contactless.ndef.NDEFRecordType;
//#endif

/**
 *
 * @author emarkki
 */
public class OtherAlgSigner extends Signer {

    public static final int ALGORITHM_ID = 0x05;

    public OtherAlgSigner(PrivateKey privateKey, int certificateType, CertificateBytes[] chain, URIRecord certURI, NDEFRecordType signatureRecordType) {
        super(ALGORITHM_ID, privateKey, certificateType, chain, certURI, signatureRecordType);
    }

    public byte[] sign(byte[] coveredBytes) throws SignatureException {
        Digest digest = new MD5Digest();
        byte[] out = new byte[digest.getDigestSize()];
        digest.update(coveredBytes, 0, coveredBytes.length);
        digest.doFinal(out, 0);
        return out;
    }

}
